package com.eamois.dao.manual.impl;

import java.sql.SQLException;
import java.util.Collection;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.eamois.dao.impl.BaseDaoImpl;
import com.eamois.dao.manual.DiagramPartDao;
import com.eamois.domain.manual.Diagram;
import com.eamois.domain.manual.DiagramPart;

public class DiagramPartDaoImpl extends BaseDaoImpl<DiagramPart> implements DiagramPartDao{

	@SuppressWarnings("unchecked")
	public Collection<DiagramPart> findDiagramPartByDiagram(final Diagram diagram) {
		// TODO Auto-generated method stub
		return (Collection<DiagramPart>)this.getHibernateTemplate().execute(new HibernateCallback() {
			
			@Override
			public Object doInHibernate(Session session) throws HibernateException,
					SQLException {
				// TODO Auto-generated method stub
				Criteria criteria = session.createCriteria(DiagramPart.class);
				criteria.add(Restrictions.eq("diagram", diagram));
				return criteria.list();
			}
		});
	}

}
